<template>
  <div class="hello">
    <h1>这是直接获取的值{{ this.$store.state.count }}</h1>
    <h1>这是通过getters获取的值{{ this.$store.getters.getStateCount }}</h1>

    <button @click="addFun">+</button>
    <button @click="reductionFun">-</button>

    <div style="border: 1px solid red;margin-top:50px;">{{ count1 }}</div>

  </div>
</template>


<script>
  import {mapState, mapActions, mapGetters} from 'vuex';
export default {
  name: 'HelloWorld',
  data () {
    return {
      msg: 'Welcome to Your Vue.js App'
    }
  },
  computed: {
    ...mapState({
      count1: state =>state.count
    })
  },
  methods: {
    addFun() {
      var n = 3;
      this.$store.dispatch("addFun", n);
    },
    reductionFun() {
      this.$store.dispatch("reductionFun");
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1, h2 {
  font-weight: normal;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>
